version 14.2
#delimit ;
log using "F:\Government Formation in Asian-Pacific Democracies.log", replace;
set more off;

* ***************************************************************** *;
* ***************************************************************** *;
* File-Name: model3_pp_f1_2.do *;
* Date: 5/30/2022 *;
* Author: MG *;
* Purpose: Marginal Effect Polot [Coalition Clusters](Presidential Formateur: Party Institutionalization) *;
* Input File: data_stata_pp.dta *;
* Data Output: None *;
* Previous file: None *;
* Machine: laptop *;
* **************************************************************** *;
* **************************************************************** *;

use "F:\Government Formation in Asian-Pacific Democracies\Portfolio Allocation\data_stata_pp.dta", clear;


gen portfolioshare = . ;

replace portfolioshare = party_port2/gov_port2 ;

gen seatshare = . ;

replace seatshare = party_seats/gov_seats ;

gen parliamentary = . ;
 
replace parliamentary = 1 if presidential ==0 ;

replace parliamentary = 0 if presidential == 1 ;

gen seatshare_parl = . ;

replace seatshare_parl = seatshare * parliamentary ;

gen formateur_parl = . ;

replace formateur_parl = formateur * parliamentary ;

gen seat_partyinst = . ;

replace seat_partyinst = seatshare * party_inst ;

gen partyinst_parl = . ;

replace partyinst_parl = party_inst * parliamentary ;

gen formateur_partyinst = . ;

replace formateur_partyinst = formateur * party_inst ;

gen form_partyinst_parl = . ;

replace form_partyinst_parl = formateur * party_inst * parliamentary ;

gen seat_partyinst_parl = . ;

replace seat_partyinst_parl = seatshare * party_inst * parliamentary ;

************************* ;
*  Summarize variables    ;
************************* ;

sum;


********************************************************************** ;
*  Table 1, Model 3, re-arranged to put seatshare IVs last           ;
* Y = b0 + b1X + b2W + b3Z + b4XW + b5XZ + b6WZ * b7XZW + controls + e ;
*    formateur is X, parliamentary is W, party_inst is Z               ;
* formateur_parl is XW, formateur_partyinst= XZ, partyinst_parl is WZ, ; 
* form_partyinst_parl is XWZ, then control variables                   ; 
********************************************************************** ;

regress portfolioshare formateur parliamentary party_inst 
formateur_parl formateur_partyinst partyinst_parl 
form_partyinst_parl 
seatshare seatshare_parl seat_partyinst seat_partyinst_parl, cluster(cabinetcode) ;

**************************************************************** ;
*  grab the elements of the estimated coefficient vector and     ;
*  the variance-covariance matrix                                ;
**************************************************************** ;

matrix b=e(b);
matrix V=e(V);

scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];
scalar b7=b[1,7];

scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];
scalar varb6=V[6,6];
scalar varb7=V[7,7];
scalar covb1b5=V[1,5];

scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb2 varb3 varb4 varb5 varb6 varb7 covb1b5;

estat vce;

* **************************************************************** *;
*     Calculate data necessary for  marginal effect plot           *;
*       Create values for horizontal axis                          *;
* **************************************************************** *;

set obs 1000;

gen MVZ = (_n-1)/1000;

replace MVZ=. if _n>1000;


* **************************************************************** *;
* We want to calculate the marginal effect of X (formateur) on     *;
* Y (portfolioshare) for all values of the modifying variable Z    *;
* (partyinst). We want to calculate this marginal effect when Z    *;
* changes for a specific value of the second modifying variable W  *;
* (parliamentary), when W = 0 (presidential regimes)               *;
* **************************************************************** *;

gen marginal_formateur = b1+b5*MVZ;

gen se_formateur = sqrt(varb1+varb5*(MVZ^2)+2*MVZ*covb1b5);

gen bound = 1.96*se_formateur;

gen upper = marginal_formateur+bound;

gen lower = marginal_formateur-bound;

gen yline=0;

*gen conb0=b1+b4*0+b5*MVZ+b7*(0*MVZ) if _n<100;



*     ****************************************************************  *;
*     Produce Figure 1.1(b): Effect of Formateur on Portfolioshare      *;
*     over range of Party Institutionalization values (presidential)    *;
*     ****************************************************************  *;

graph twoway hist party_inst if parliamentary==0 & party_inst<1, width(0.04) percent color(gs15) yaxis(2)
    || line marginal_formateur MVZ if MVZ<1 & MVZ>0, clpattern(solid) clwidth(medthick) clcolor(black) yaxis(1)
    || line lower MVZ if MVZ<1 & MVZ>0, clpattern(dash) clwidth(thin) clcolor(red)
    || line upper MVZ if MVZ<1 & MVZ>0, clpattern(dash) clwidth(thin) clcolor(red)
    || line yline MVZ, clpattern(solid) clwidth(thin) clcolor(black)
    ||,
    xlabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, nogrid labsize(2.5))
    ylabel(-1.0 -0.75 -0.5 -0.25 0 0.25 0.5 0.75 1 1.25 1.5 1.75 2, axis(1) nogrid labsize(2.5))
    ylabel(0 10 20 30 40, axis(2) nogrid labsize(2.5) labcolor(gs12) tlcolor(gs12))
        yscale(noline alt)
        yscale(noline alt axis(2))
        xscale(noline)
        legend(off)
        title("{stSerif:(b) Party Institutionalization and Formateur Bonus}",  size(3.5))
        xtitle("{stSerif:Party Institutionalization}",  size(3) height(7) )
        ytitle("{stSerif:Percentage of Observations}", color(gs12) axis(2) size(3) margin(5 0 0 0))
        ytitle("{stSerif:Marginal Effect of Formateur}", size(3) height(7)) 
        scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)); 

      
graph export "F:\Government Formation in Asian-Pacific Democracies\Portfolio Allocation\model5.wmf", replace; 
 
 
 
 
log close;
exit;

